package com.wavehi.login.web.controller;

import com.wavehi.login.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author WaveHi
 * @Date 25/10/2021 下午 7:49
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/exist")
    @ResponseBody
    public String exist(String username) {
        //Check data
        username = username.trim();
        if("".equals(username)) {
            return "Your should write you username";
        }
        //Judge whether user exists.
        Boolean existUser = userService.existUser(username);
        //Response message according to result.
        if(existUser) {
            return "Username is right.";
        }

        return "Username is incorrect!";
    }
}
